package HashMap;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author Administrator
 * @ClassName HashMap
 * @TIME 星期四 2020/12/31
 */
public class HashMapTest {
    public static void main(String[] args) {
        RunableDemo r = new RunableDemo();
        new Thread(r).start();
    }
}

class RunableDemo implements Runnable {
    @Override
    public void run() {
        Map<String, Integer> map = new HashMap<>();
        map.put("A", 1);
        map.put("B", 2);
        map.put("C", 3);
        map.put("D", 4);
        System.out.println("输出: " + map);
        System.out.println("删除: " + map.remove("A"));
        System.out.println("查询: " + map.get("D"));
        System.out.println("长度: " + map.size());
        System.out.println("判断Key: " + map.containsKey("B"));
        System.out.println("判断Value: " + map.containsValue(4));
        System.out.println("判断是否为空: " + map.isEmpty());
        System.out.println("keySet" + map.keySet());
        Set<String> set = map.keySet();
        for (String s : set) {
            System.out.println(map.get(s));
        }
        //遍历 键
        Collection<String> c = map.keySet();
        for (String s : c) {
            System.out.println(s);
        }
        //遍历 值
        Collection<Integer> d = map.values();
        for (Integer s : d) {
            System.out.println(s);
        }
    }
}
